package com.zhenzhang.myblog.entity.role;

import com.zhenzhang.myblog.utils.SecureUtils;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class User {
    private Integer id = 0;
    private String username = "";
    private String password = "";
    private Boolean admin = false;
    private String headImage = "";
    private String email = "";


    public void setPassword(String raw) {
        if (raw == null || raw.equals("")) {
            this.password = null;
        } else {
            password = SecureUtils.encodePassword(raw);
        }
    }

    /**
     * 判断给定的密码是否与当前用户的密码相等
     * @param input 输入的密码
     * @return      相等返回true，否则返回false
     */
    public boolean isPasswordEqual(String input) {
        return SecureUtils.encodePassword(input).equals(this.password);
    }
}
